package cn.creat.zhxy.controller;

import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Map;
import java.util.Properties;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.creat.zhxy.po.CurrentRoom;
import cn.creat.zhxy.service.CurrentRoomService;

@Controller
@RequestMapping(value="/room")
public class CurrentRoomController {
	
	@Autowired
	private CurrentRoomService currentRoomService;

	private static String currentRoomUrl;
	private static String roomListUrl;
	static{
		InputStream inStream = CurrentRoomController.class.getClassLoader().getResourceAsStream("urls.properties");
		Properties properties = new Properties();
		try {
			properties.load(inStream);
			CurrentRoomController.setCurrentRoomUrl(properties.getProperty("currentRoomUrl"));
			CurrentRoomController.setRoomListUrl(properties.getProperty("roomListUrl"));
			try {
				properties.load(inStream);
			} catch (IOException e) {
				e.printStackTrace();
			}finally{
				if(inStream != null){
					try {
						inStream.close();
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			}
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
	}
	
	@RequestMapping(value="/getCurrentRoom")
	public @ResponseBody Map<Integer, CurrentRoom[]> getCurrentRoom() throws Exception{
		int[] ids = new int[4];
		ids[0] = 164;
		ids[1] = 166;
		ids[2] = 167;
		ids[3] = 163;
		return currentRoomService.getAllCurrentRoom(
				CurrentRoomController.getRoomListUrl(), 
				CurrentRoomController.getCurrentRoomUrl(), ids);
	}
	
	
	public static String getCurrentRoomUrl() {
		return currentRoomUrl;
	}
	public static void setCurrentRoomUrl(String currentRoomUrl) {
		CurrentRoomController.currentRoomUrl = currentRoomUrl;
	}


	public static String getRoomListUrl() {
		return roomListUrl;
	}


	public static void setRoomListUrl(String roomListUrl) {
		CurrentRoomController.roomListUrl = roomListUrl;
	}
}
